<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编号">
              <a-input placeholder="请输入项目编号" v-model="queryParam.projectFinalNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经营团队">
              <select-team-input v-model="queryParam.teamName" :tdlx="1" :teamType="0"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="生产团队">
              <select-team-input v-model="queryParam.productTeam" :tdlx="2"  :teamType="0"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目承接人">
              <select-user-by-dep
                placeholder="请选择项目承接人"
                v-model="queryParam.undertaker"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目负责人">
              <select-user-by-dep
                placeholder="请选择项目负责人"
                v-model="queryParam.projectLeading"
              />
            </a-form-item>
          </a-col>
          <a-col ::xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="考核日期" :labelCol="labelCol">
              <a-month-picker style="width: 100%;" valueFormat = 'YYYY-MM-DD' placeholder="请选择考核日期" picker="month" :allowClear="false" v-model="queryParam.examineTime"  />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="newSearchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls(exportTitle)">导出</a-button>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:2000}"
        :components="drag(columns)"
        bordered
        rowKey="id"
        :pagination="ipagination"
        :columns="columns"
        :data-source="dataSource"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <a slot="projectName" slot-scope="text, record" @click="getDetail(record.projectId)">{{ text }}</a>
      </a-table>
    </div>
    <!-- 项目详情开始 -->
    <erp-project-report-modal  ref="modalForm"></erp-project-report-modal>
  </a-card>
</template>
<script>
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin';
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin';
import { mixinDevice } from '@/utils/mixin'
import BusinessCategoryNameSelect from '@views/erp/components/BusinessCategoryNameSelect'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import { getAction } from '@/api/manage';
import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
import Pagination from './Pagination'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import moment from 'moment'
import {tableDragResize} from '@/utils/draggable-multistage'
export default {
  name: 'ErpAuditCollectMoneyList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin,tableDragResize],
  components: {
    ErpProjectReportModal,
    BusinessCategoryNameSelect,
    SelectCompanyInput,
    SelectTeamInput,
    Pagination,
    SelectUserByDep
  },
  data() {
    return {
      // 禾美集团xxxx年xx月应收款项目负责人
      exportTitle: '禾美集团' + moment().format('YYYY年MM月') + '应收款项目负责人考核结果',
      rowSpanPagination: {
        pageNo: 1,
        pageSize: 5,
        totalPage: 0,
        total: 0
      },
      //列设置
      settingColumns:[],
      columns:[],
      defColumns: [
        { title: '项目编号',
          dataIndex: 'projectFinalNo',
          align: 'center',
          ellipsis: true,
          width: 200
        },
        { title: '项目名称',
          dataIndex: 'projectName',
          align: 'center',
          width: 200,
          scopedSlots: { customRender: 'projectName' },
          ellipsis: true
        },
        { title: '经营团队',
          dataIndex: 'teamName_dictText',
          align: 'center',
          width: 200,
          ellipsis: true
        },
        { title: '项目承接人',
          dataIndex: 'undertakerName',
          align: 'center',
          width: 200,
          ellipsis: true
        },
        { title: '工号',
          dataIndex: 'undertakerWorkNo',
          align: 'center',
          width: 200,
          ellipsis: true
        },
        { title: '业务分类',
          dataIndex: 'categoryName',
          align: 'center',
          width: 200,
          ellipsis: true
        },
        { title: '生产团队',
          dataIndex: 'productTeam_dictText',
          align: 'center',
          width: 200,
          ellipsis: true
        },
        { title: '项目负责人',
          dataIndex: 'projectLeading_dictText',
          align: 'center',
          width: 200,
          ellipsis: true
        },
        {
          title: '考核期应收账款',
          dataIndex: 'examine',
          children: [
            { title: '应收金额（元）',
              dataIndex: 'examineCollectMoney',
              align: 'center',
              ellipsis: true,
              width: 200
            },
            { title: '实收金额（元）',
              dataIndex: 'examineRealCollectMoney',
              align: 'center',
              ellipsis: true,
              width: 200,
            },
            { title: '差额（元）',
              dataIndex: 'examineDifference',
              align: 'center',
              width: 200,
              ellipsis: true
            },
            { title: '回款率(%)',
              align: 'center',
              dataIndex: 'examineComplateRate',
              width: 200,
              ellipsis: true
            },
            { title: '奖罚金额（元）',
              align: 'center',
              ellipsis: true,
              width: 200,
              dataIndex: 'examineAchievementMoney'
            }
          ]
        },
        {
          title: '后延一个月回款考核',
          dataIndex: 'lastMonth',
          children: [
            { title: '应收金额（元）',
              dataIndex: 'lastMonthCollectMoney',
              align: 'center',
              ellipsis: true,
              width: 200
            },
            { title: '实收金额（元）',
              dataIndex: 'lastMonthRealCollectMoney',
              align: 'center',
              ellipsis: true,
              width: 200
            },
            { title: '差额（元）',
              dataIndex: 'lastMonthDifference',
              align: 'center',
              width: 200,
              ellipsis: true
            },
            { title: '回款率(%)',
              align: 'center',
              dataIndex: 'lastMonthComplateRate',
              width: 200,
              ellipsis: true
            },
            { title: '奖罚金额（元）',
              align: 'center',
              ellipsis: true,
              width: 200,
              dataIndex: 'lastMonthAchievementMoney'
            }
          ]
        },
        {
          title: '后延两个月回款考核',
          dataIndex: 'secondMonth',
          children: [
            { title: '应收金额（元）',
              dataIndex: 'lastSecondMonthCollectMoney',
              align: 'center',
              ellipsis: true,
              width: 200
            },
            { title: '实收金额（元）',
              dataIndex: 'lastSecondMonthRealCollectMoney',
              align: 'center',
              ellipsis: true,
              width: 200
            },
            { title: '差额（元）',
              dataIndex: 'lastSecondMonthDifference',
              align: 'center',
              width: 200,
              ellipsis: true
            },
            { title: '回款率(%)',
              align: 'center',
              dataIndex: 'lastSecondMonthComplateRate',
              width: 200,
              ellipsis: true
            },
            { title: '奖罚金额（元）',
              align: 'center',
              ellipsis: true,
              width: 200,
              dataIndex: 'lastSecondMonthAchievementMoney'
            }
          ]
        },
        {
          title: '当月应收考核总计',
          dataIndex: 'total',
          children: [
            { title: '应收金额（元）',
              dataIndex: 'totalCollectMoney',
              align: 'center',
              ellipsis: true,
              width: 200
            },
            { title: '实收金额（元）',
              dataIndex: 'totalRealCollectMoney',
              align: 'center',
              ellipsis: true,
              width: 200
            },
            { title: '差额（元）',
              dataIndex: 'totalDifference',
              align: 'center',
              width: 200,
              ellipsis: true
            },
            { title: '奖罚金额（元）',
              align: 'center',
              ellipsis: true,
              width: 200,
              dataIndex: 'totalAchievementMoney'
            }
          ]
        }
      ],
      url: {
        c: '/api/erp/project/report/erpProjectReport/queryById',
        list: '/api/erp/project/report/erpReceivableAccountsReportController/list',
        queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
        exportXlsUrl: '/api/erp/project/report/erpReceivableAccountsReportController/exportDetailXls'
      }
    }
  },
  created(){
    this.$set(this.queryParam,'examineTime',moment(new Date()).format('YYYY-MM'))
  },
  methods: {
    newSearchReset(){
      this.onClearSelected();
      if (this.bizTaskType) {
        this.queryParam = {bizTaskType: this.bizTaskType};
      }
      this.$set(this.queryParam,'examineTime',moment(new Date()).format('YYYY-MM'))
      this.loadData(1);
    },
    getDetail(id) {
      const that = this
      this.$nextTick(() => {
        getAction(this.url.queryProjectReportById, { id }).then((res) => {
          if (res.success) {
            const model = res.result
            that.$refs.modalForm.getDetail(model);
            that.$refs.modalForm.title = '项目一览表';
          }
        })
      })
    },
    businessCategoryHandle(obj) {
      if (obj) {
        this.queryParam.categoryCode = obj.categoryCode;
      }
    }
  }
}
</script>
